//
//  YuEZhiFuVC.m
//  代理端
//
//  Created by sliver on 15/12/25.
//  Copyright (c) 2015年 sliver. All rights reserved.
//

#import "YuEZhiFuVC.h"
#import "Unit.h"
#import "WXDataService.h"
#import "ShoppingMainVC.h"
@interface YuEZhiFuVC ()<UITextFieldDelegate,BackViewDeleget>
{
    UITextField *telTextField;
}
@end

@implementation YuEZhiFuVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadNav];
    [self loadMainView];
    // Do any additional setup after loading the view.
}
-(void)loadMainView{
    telTextField = [[UITextField alloc]initWithFrame:CGRectMake(WITH_FOR_40, WITH_FOR_100, ScreenW-WITH_FOR_80,WITH_FOR_40)];
    telTextField.delegate = self;
    telTextField.textColor = [UIColor grayColor];
    telTextField.font = [UIFont systemFontOfSize:18.0];
    telTextField.placeholder = @"请输入支付密码";
    telTextField.backgroundColor = [UIColor whiteColor];
    telTextField.textAlignment = NSTextAlignmentCenter;
    
    telTextField.layer.masksToBounds = YES;
    telTextField.layer.cornerRadius = 5;
    telTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    telTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    telTextField.returnKeyType = UIReturnKeyDone;
    telTextField.secureTextEntry =YES;
     [self.view addSubview:telTextField];
    
    //确认按钮
    UIButton *landBtn = [[UIButton alloc]initWithFrame:CGRectMake(60, ScreenH - 100, ScreenW - 120, 40)];
    landBtn.backgroundColor = DRINK_RED_COLOR;
    landBtn.layer.masksToBounds = YES;
    landBtn.layer.cornerRadius = 5;
    [landBtn setTitle:@"确定" forState:UIControlStateNormal];
    landBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [landBtn addTarget:self action:@selector(clickLand:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:landBtn];

}
#pragma mark - 支付
-(void)clickLand:(UIButton *)senfer{
     NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    [MyMbd addHudToView:self.view];
    [params setObject:USER_ACCOUNT forKey:@"agency_id_"];
    [params setObject:_sum_money forKey:@"total_money"];
    [params setObject:telTextField.text forKey:@"pay_pass"];
    [params setObject:_order_id forKey:@"order_id_"];
    [WXDataService requestWithURL:@"mobile/agency/payByBalance.jhtml" params:params httpMethod:@"POST" block:^(id result, NSString *success, NSString *msg) {
        [MyMbd hidenHudFromView:self.view];
        [BackView addToview:self.view WithDeleget:self WithMessage:msg WithBtnCount:1];
//        ShoppingMainVC *shopvc = [[ShoppingMainVC alloc]init];
//        [self presentViewController:shopvc animated:YES completion:nil];
        return;
    }failblock:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

#pragma mark - nav
-(void)loadNav{
    self.view.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    UIView *redview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    redview.backgroundColor = DRINK_RED_COLOR;
    [self.view addSubview:redview];
    UILabel *redLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenW, 40)];
    redLab.backgroundColor = DRINK_RED_COLOR;
    redLab.text = @"输入支付密码";
    redLab.textColor = [UIColor whiteColor];
    redLab.textAlignment =  NSTextAlignmentCenter;
    redLab.font = [UIFont boldSystemFontOfSize:19];
    [self.view addSubview:redLab];
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 20,44, 40)];
    backBtn.adjustsImageWhenHighlighted = NO;
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
}
-(void)clickBack{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [telTextField resignFirstResponder];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)makeSureButtenClic:(UIButton *)btn withMessage:(NSString *)message
{
    if ([message isEqualToString:@"余额支付成功"]) {
        [self dismissViewControllerAnimated:YES completion:nil];
        self.block();

    }
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
